/**
 * Created by MyPC on 2017/6/21.
 */
let fs = require('fs');
let path = require('path');

// 判断路径是否存在,不存在则创建
function mkdir(dirpath, mode) {
  if (!fs.existsSync(dirpath)) {
    let pathtmp;
    console.log(dirpath)
    dirpath.split(path.sep).forEach(function(dirname) {
      if (pathtmp) {
        pathtmp = path.join(pathtmp, dirname);
      }
      else {
        pathtmp = dirname;
      }
      if (dirname.indexOf('.')===-1 && !fs.existsSync(pathtmp)) {
        if (!fs.mkdirSync(pathtmp, mode)) {
          return false;
        }
      }
    });
  }
  return true;
}
module.exports.mkdir = mkdir;
